package com.snailcatmall.www.serversocket.tools;

import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

import java.nio.ByteBuffer;


/**
 * @deprecated 禁用
 * @see ServerCurrentSocket 官方目前推荐使用 ChannelHandlerAdapter
 */
public class ServerCurrentSocket extends ChannelHandlerAdapter {


    @Override
    public void channelRegistered(ChannelHandlerContext ctx){

    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
        Channel channel = ctx.channel();
        if(channel.isActive()){
            GlobalStaticClass.channelHandlerContextMap.remove(ctx);
            System.out.println("当前在线人数: " + GlobalStaticClass.channelHandlerContextMap.size() +" 位");
            ctx.close();
        }
    }
}
